package com.jy.unkown;

import com.jy.common.BaseApplication;
import com.jy.unkown.entity.UnkownAdBean;
import com.jy.unkown.view.UnkownADView;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;

public class UNKOWN {
    public static HashMap<String, UnkownAdBean> unkownAdBeanHashMap = new HashMap<>();

    public static final String UNKOWN_AD_KEY = "UNKOWN_AD_KEY";


    public static void addAD(String key, UnkownAdBean unkownAdBean) {
        unkownAdBeanHashMap.put(key, unkownAdBean);
    }

    public static UnkownAdBean getAd(String key) {
        return unkownAdBeanHashMap.get(key);
    }
    public static Map<String, AdCallBack> callBackHashMap = Collections.synchronizedMap(new WeakHashMap<>());


    public static void addAdCallBack(String key,AdCallBack adCallBack){
        callBackHashMap.put(key,adCallBack);
    }

    public static   AdCallBack  getAdCallBack(String key){
        return callBackHashMap.get(key);
    }







    static HashMap<String, UnkownADView.ProxyDownListener> hashMap = new HashMap<>();

    public static void addListener(String key, UnkownADView.ProxyDownListener proxyDownListener) {
        hashMap.put(key, proxyDownListener);
    }

    public static void notifyDownload(String key, String downUrl) {
        UnkownADView.ProxyDownListener proxyDownListener = hashMap.get(key);
        if (proxyDownListener != null) {
            proxyDownListener.download(downUrl);
        }
    }


    public static int dpToPx(int dp) {
        float density = BaseApplication.getBaseApplication().getResources().getDisplayMetrics().density;
        return Math.round(dp * density);
    }

    public static int pxToDp(int px) {
        float density = BaseApplication.getBaseApplication().getResources().getDisplayMetrics().density;
        return Math.round(px / density);
    }
}
